Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GROOVY-5403 Add grep to Iterator, to return a new filtered Iterator #40

Closed
wants to merge 2 commits into from

Conversation

timyates
Copy link
Member

https://jira.codehaus.org/browse/GROOVY-5403

grep currently works on collections, but it would be nice to have it work on Iterators

We could then do lazy things like:

// Set our initial value
def a = 1
// Define an iterator around this value
def iter = [ hasNext:{ true }, next:{ a++ } ] as Iterator

// Define a new iterator that will just emit odd numbers
def oddIter = iter.grep { it % 2 }

// Check it's working
assert [ 1, 3, 5 ] == oddIter.take( 3 ).collect()

@blackdrag
Copy link
Member

See comment on https://jira.codehaus.org/browse/GROOVY-5403

@blackdrag blackdrag closed this Jan 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants